package com.gtfrank.web.servlet.day1;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Date;

/**
 * @ProjectName: sudacoursetrainging
 * @ClassName: ShowTimeServlet
 * @PackageName:com.gtfrank.web.servlet.day1
 * @Description: 提供一个显示几点的服务
 * @Author: frank
 * @Date: 2021/4/23 14:18
 * @Version v1.0
 */
@WebServlet(value = "/day1/showTimeServlet")
public class ShowTimeServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        //你要显示到网页上去  所以你要告诉网页你从服务器过去的是mime格式
        response.setContentType("text/html");
        //文本格式
      //  response.setContentType("text/plain");
        response.setCharacterEncoding("utf-8");
        Date date = new Date();
        //通过System打印只能显示在服务器后台  客户端是看不到
       // System.out.println(date);
        //出现我要把date 写到浏览器去
        // 写---IO流    输出 输入  输出
       // FileOutputStream out = new FileOutputStream(new File(new 浏览器));
        PrintWriter out = response.getWriter();
        out.println("<html>");
        out.println("<head>");
        out.println("	<title>显示时间</title>");
        out.println("</head>");
        out.println("<body>");
        out.println("现在的时间是"+new Date());
        out.println("</body>");
        out.println("</html>");
        out.flush();
        out.close();

    }
}
